<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ProductListResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id'                => $this->id,
            'spec_type'         => $this->spec_type,
            'type'              => $this->type,
            'cate_id'           => $this->product_cate_id,
            'freight_id'        => $this->freight_id,
            'title'             => $this->title,
            'long_title'        => $this->long_title,
            'description'       => $this->description ?? '',
            'image'             => $this->image,
            'rating'            => $this->rating,
            'sold_count'        => $this->sold_count,
            'review_count'      => $this->review_count,
            'commission_ratio'  => $this->commission_ratio,
            'price'             => $this->price,
            'original_price'    => $this->original_price,
            'coupon_count'      => $this->coupons()->count(),
            'is_shipping'       => $this->is_shipping  // 是否包邮
        ];
    }
}
